<?php
/**
 * Created by PhpStorm.
 * User: *!N.J
 * Date: 2021/8/25
 * Time: 1:18
 * QQ:1467572213
 */

namespace app\admin\model;

use think\Model;
use think\Db;
use think\facade\Config;
use think\facade\Session;

class Recharge extends Model
{
    public static function index($keyword,$p_order_id,$create_time,$status)
    {
        date_default_timezone_set('America/Mexico_City');
        $map = [];
        $map[]=['is_status','=',1];
        if ($keyword) {
            $map[] = ['username', 'like', '%'.trim($keyword).'%'];
        }
        if ($p_order_id) {
            $map[] = ['p_order_id', '=', $p_order_id];
        }
        if ($create_time) {
            $create_time1 =$create_time.' 00:00:00';
            $create_time2 =$create_time.' 23:59:59';
            $map[] = ['create_time', '>', strtotime($create_time1)];
            $map[] = ['create_time', '<', strtotime($create_time2)];
        }
        if ($status) {
            if($status==2){
                $status=0;
            }
            $map[] = ['status', '=', $status];
        }
        
            // print_r($map);die;
        $list = Db::name('fd_recharge')
        ->where($map)
        ->order('id', 'desc')
        ->paginate(50, false, ['query' => request()->param()]);
        return $list;
        // else {
        //     // $list = Db::name('fd_recharge')->where('is_status',1)->order('id', 'desc')
        //     //     ->paginate(50, false, ['query' => request()->param()]);
        //     // return $list;
        // }
    }
    
    public static function indexs($keyword)
    {
        if ($keyword) {
            $list = Db::name('fd_recharge')->where('username', $keyword)
                ->paginate(10, false, ['query' => request()->param()]);
            return $list;
        } else {
            $list = Db::name('fd_recharge')->order('id', 'desc')
                ->paginate(10, false, ['query' => request()->param()]);
            return $list;
        }
    }

    public static function sum($keyword)
    {
        if ($keyword){
            $list = Db::name('fd_recharge')->where('username', $keyword)->where('status',1)->sum('money');
            return $list;
        }
    }

    public static function recharge_mode()
    {
        return Db::name('fd_recharge_api')->select();
    }

    public static function recharge_add($info)
    {
        $add = Db::name('fd_recharge_api')->insert($info);
        if ($add == true){
            return 'success';
        }else{
            return 'error';
        }
    }

    public static function recharge_status($id,$status)
    {
        $status = Db::name('fd_recharge_api')->where('id',$id)->setField('status',$status);
        if ($status == true){
            return 'success';
        }else{
            return 'error';
        }
    }


}